package com.company.restaurant.service.codec;

import com.company.restaurant.dto.BaseMessage;
import com.google.gson.Gson;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description of class.
 * Created 3/26/14 5:17 PM
 *
 * @author andrey.rodin@playtech.com
 */

@Service
public class JsonEncoder extends MessageToMessageEncoder<String> {

    @Resource
    private Gson gson;

    @Override
    protected void encode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
        BaseMessage message = gson.fromJson(msg, BaseMessage.class);
        out.add(message);
    }
}
